package com.project.personalfundmanager.client;

import com.extjs.gxt.ui.client.widget.MessageBox;
import com.extjs.gxt.ui.client.widget.Viewport;
import com.google.gwt.user.client.ui.RootPanel;
import com.project.personalfundmanager.client.listeners.CalculateTaxListener;
import com.project.personalfundmanager.client.listeners.SlabInfoListener;
import com.project.personalfundmanager.client.listeners.TaxInputListener;

public class Application
{
	static Viewport viewPort;
	boolean isWoman = false;
	boolean isSeniorCitizen = false;

	public Application()
	{
		if ( viewPort == null )
		{
			viewPort = new Viewport();
			RootPanel.get().add( viewPort );
		}
		viewPort.setSize( "100%", "100%" );
	}

	public void load()
	{
		showTaxInputPanel();
		viewPort.layout( true );
	}

	private void showTaxInputPanel()
	{
		viewPort.removeAll();
		viewPort.add( new TaxInputPanel( new TaxInputListener()
		{
			public void actionPerformed()
			{
				showSlabInformation();
			}
		} ) );
		viewPort.layout( true );
	}

	protected void showSlabInformation()
	{
		viewPort.removeAll();
		new SlabInfoWindow( new SlabInfoListener()
		{
			public void back()
			{
				showTaxInputPanel();
			}

			public void goAhead( boolean isWoman, boolean isSeniorCitizen )
			{
				showCalculatedTaxPanel( isWoman, isSeniorCitizen );
			}
		} );
	}

	private void showCalculatedTaxPanel( boolean isWoman, boolean isSeniorCitizen )
	{
		viewPort.removeAll();
		viewPort.add( new CalculatedTaxPanel( isWoman, isSeniorCitizen ).getPanel( new CalculateTaxListener()
		{
			public void back()
			{
				showTaxInputPanel();
			}

			public void submit()
			{
				MessageBox.info( "Not Implemented", "This functionality is not yet implemented.", null );
			}
		} ) );
		viewPort.layout( true );
	}
}
